<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">通用大数据框架智能计算引擎优化仿真平台</el-breadcrumb-item>
      <el-breadcrumb-item>计算任务</el-breadcrumb-item>
      <el-breadcrumb-item>计算管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query"  class="input-with-select" clearable>
            <el-button slot="append" icon="el-icon-search" ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table
          :data = "CalculateList"
          border
          style="width: 100%">
        <el-table-column
            prop="filename"
            label="计算名称"
            width="200">
        </el-table-column>
        <el-table-column
            prop=""
            label="类别"
            width="180">
        </el-table-column>
        <el-table-column
            prop="createtime"
            label="创建时间"
            width="200">
        </el-table-column>
        <el-table-column
            prop="updateman"
            label="创建人"
            width="200">
        </el-table-column>

        <el-table-column
            prop="operate"
            label="操作"
            width="360">
          <template v-slot="scope">
            <el-tooltip class="item" effect="dark" content="编辑计算" placement="top">
              <el-button type="primary" icon="el-icon-edit"  @click="editCalculate(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除计算" placement="top">
              <el-button type="danger" icon="el-icon-delete" @click="removeCalculate(scope.row)" ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @size-change="SizeChange"
          @current-change="CurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[10,20,30]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>

    </el-card>
    <el-dialog
        title="编辑计算"
        :visible.sync="editCalculateVisble"
        width="30%"
        @close="closeeditCalculateDialog"
    >

      <el-form :model=" editCalculateParams" :rules="editCalculateFormRul" ref="editCalculateFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="计算名称" prop="optimizeschemenamename" >
          <el-input v-model="editCalculateParams.Calculatename"  ></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="editCalculateVisble = false">取 消</el-button>
     <el-button type="primary" @click="editCalculateList">确 定</el-button>
     </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data(){
    return{
      queryInfo:{
        //查询参数
        query:'',
        pagenum:1,
        pagesize:10
      },
      CalculateList:[],
      test:[
       ],
      editCalculateParams:{},
      editCalculateVisble:false,
      editCalculateFormRul:{}
    }
  },
  methods:{
    SizeChange(newsize){
      this.queryInfo.pagesize = newsize
      this. getoptimizeSchemeList()
    },
    CurrentChange(newnumber){
      this.queryInfo.pagenum = newnumber
      this. getoptimizeSchemeList()
    },
    editCalculate(row){
      this.editCalculateParams = row
      this.editCalculateVisble = true

    },
    closeeditCalculateDialog(){
      this.$refs.editCalculateFormRef.resetFields()
    },
    editCalculateList(){
      this.$http.put(`/${this.editCalculateParams.Calculateid}`,this. editCalculateParams).then(res=>{
        if(res.data.meta.status !== 200) return this.$message.error('更新失败')
        this.getCalculateList()
      })
    },
    getCalculateList() {
      // this.$http.get('',{params:this.queryInfo}).then(res=>{
      //   if(res.data.meta.status !== 200)
      //     return this.$message.error('请求优化方案列表失败')
      //
      // })
      this.optimizeSchemeList = this.test
      this.total = 0
    },
    removeCalculate(row){
      this.$confirm('此操作将永久删除'+row.Calculatename+', 是否继续?', '删除计算', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.delete(`/${row.Calculateid}`).then(res=>{
          if(res.data.meta.status !== 200) return this.$message.error('删除失败')
          this.$message.success('删除成功')
          this.getCalculateList()
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
  created() {
    this.getCalculateList()
  }
}
</script>
<style>

</style>
